package com.mysoft.gfyx.marketdevelop.service.dto;

import lombok.Data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class PickProjectsDto implements Comparable<PickProjectsDto> {
    private String date;

    private String city;

    private String id;

    private String no = "-";

    private String type;

    private String province_code;

    private String title;

    @Override
    public int compareTo(PickProjectsDto p) {
        if (p.getDate().equals("") && this.getDate().equals("")) return 0;
        if (p.getDate().equals("")) return -1;
        if (this.getDate().equals("")) return 1;

        SimpleDateFormat fromFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date pDate = fromFormatter.parse(p.getDate());
            Date tDate = fromFormatter.parse(this.getDate());
            return Math.round(pDate.getTime() - tDate.getTime());
        } catch (ParseException e) {
            return 0;
        }
    }
}
